<!-- 政策解读详情 -->
<template>
  <div class="details_main">
    <headerBar />
    <div class="mincard mindWidth">
      <span @click="$router.push('/')">首页</span>>
      <span @click="toRoute">政策解读</span>>
      <span>详情</span>
    </div>
    <div class="details_main_content">
      <div class="mindWidth">
        <div class="details_content_title">{{ articleDetails.title }}</div>
        <div class="tampTime flex items-middle space-between">
          <div>
            <span>申报时间: {{ articleDetails.declareTime }} -{{ articleDetails.deadline }}</span>
            <span>
              受理部门:
              <em
                @click="goDepartmentPage(articleDetails.departmentId)"
              >{{ articleDetails.departmentName }}</em>
            </span>
            <button
              :class="articleDetails.whetherAttention === 0 ? '' : 'active'"
              class="changeHanld"
              @click="subscribe(articleDetails.departmentId,articleDetails.whetherAttention)"
            >{{articleDetails.whetherAttention === 0 ? "订阅" : "已订阅"}}</button>
            <span class="more changeHanld" @click="toSubscriptionpage">订阅更多</span>
          </div>
          <div>
            <el-tooltip
              v-if="articleDetails.whetherCanExport===1"
              class="item"
              effect="dark"
              content="下载"
              placement="top"
            >
              <el-button class="export" @click="exportName">该项目可申报企业名单</el-button>
            </el-tooltip>
          </div>
        </div>
        <div class="declare">
          <div class="declare_title">申报条件</div>
          <div
            class="declare_centent"
            style="white-space: pre-wrap;"
            v-html="articleDetails.declareCondition"
          ></div>
        </div>
        <div class="declare">
          <div class="declare_title">支持力度</div>
          <div
            class="declare_centent"
            style="white-space: pre-wrap;"
            v-html="articleDetails.supported"
          ></div>
        </div>
        <div class="declare">
          <div class="declare_title">申报材料</div>
          <div
            class="declare_centent"
            style="white-space: pre-wrap;"
            v-html="articleDetails.materials"
          ></div>
        </div>
        <div class="declare">
          <div class="declare_title">项目来源</div>
          <div
            class="declare_centent"
            style="white-space: pre-wrap;"
            v-html="articleDetails.sourceFrom"
          ></div>
        </div>
        <span class="share changeHanld">
          <i>阅读量 {{ articleDetails.pageViewCount }}</i>
        </span>
        <el-dialog
          v-model="isShareWeChat"
          width="360px"
          :show-close="true"
          :close-on-click-modal="false"
        >
          <shareWeChat @clickWechat="showWeChat" />
        </el-dialog>
        <!-- 订阅数据已满 -->
        <el-dialog
          :visible.sync="departmentDialogVisible"
          :show-close="false"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          width="300px"
          :before-close="handleClose"
        >
          <template #footer>
            <div class="contents_qydb">
              <img src="@/static/image/cwhyts2.png" alt class="imgs_qydb" />
              <div class="goVip">
                <div class="top">{{isDepart === 1 ? '可关注数量已满' : '可下载数量已满'}}</div>
                <div class="bn">成为VIP会员畅享更多权益</div>
              </div>
              <div class="option">
                <span class="spans_qydb" @click="departmentDialogVisible = false">再用看看</span>
                <p class="ps_qydb" @click="toVipPage">升级VIP</p>
              </div>
            </div>
          </template>
        </el-dialog>
      </div>
    </div>
    <navigation />
    <footerBar />
    <!-- 登录弹窗 -->
    <login-dialog ref="login" @reload="reload"></login-dialog>
  </div>
</template>

<script>
import { commonRequest, commonRequestSsr, postRequest } from "../../api/api.js";
import shareWeChat from "../../components/shareCard/index.vue";
import {
  noticeDownloadExcel,
  whetherCanExport,
  whetherDownload,
  cancelAttention,
  departmentAttention
} from "../../api/api.js";
import { sessionTake } from "../../util/validate";
import loginDialog from "../../components/login_item/LoginDialog";
import keyWord from "../../components/keyWord.vue"; //部门订阅关键字
export default {
  components: {
    shareWeChat,
    loginDialog,
    keyWord
  },
  head() {
    return {
      title: `${this.articleDetails.title}-比目镜`,
      meta: [
        {
          hid: "keywords",
          name: "keywords",
          content: this.articleDetails.title
        },
        {
          hid: "description",
          name: "description",
          content: this.articleDetails.title
        }
      ]
    };
  },
  data() {
    return {
      articleDetails: "",
      isShareWeChat: false, // 微信分享框显示
      departmentDialogVisible: false, // 阅读量已满
      condition: "",
      policyId: this.$route.query.id,
      isDepart: 1
    };
  },
  async asyncData({ app, route, err }) {
    let id = route.params.id;
    let [res] = await Promise.all([
      commonRequestSsr("/api/pms/pmsPolicyInterpret/getPolicyInterpretInfo", {
        id
      })
    ]);
    if (res.declareCondition) {
      res.declareCondition.replace(/\r/g, "<br>");
    }
    if (res.supported) {
      res.supported.replace(/\r/g, "<br>");
    }
    if (res.materials) {
      res.materials.replace(/\r/g, "<br>");
    }
    if (res.sourceFrom) {
      res.sourceFrom.replace(/\r/g, "<br>");
    }
    return {
      articleDetails: res
    };
  },

  //方法集合
  methods: {
    // 登录刷新当前页
    reload() {
      location.reload();
    },
    toVipPage() {
      window.open("/pageVIP", "_blank");
    },
    getDetails() {
      let { id } = this.$route.query;
      commonRequest("/api/pms/pmsPolicyInterpret/getPolicyInterpretInfo", {
        id
      }).then(res => {
        this.articleDetails = res;
        this.articleDetails.declareCondition.replace(/\r/g, "<br>");
        this.articleDetails.supported.replace(/\r/g, "<br>");
        this.articleDetails.materials.replace(/\r/g, "<br>");
        this.articleDetails.sourceFrom.replace(/\r/g, "<br>");
      });
    },
    handleClose() {
      this.departmentDialogVisible = false;
    },
    goDepartmentPage(departmentId) {
      window.open("/departmentInside?id=" + departmentId, "_blank");
    },
    // 订阅
    subscribe(id, index) {
      let token = localStorage.getItem("saasToken");
      if (!token) {
        this.$refs.login.open();
        return;
      }
      if (index === 0) {
        this.$refs.keyWord.open(id);
      } else {
        cancelAttention(id).then(res => {
          if (res.code === 200) {
            this.articleDetails.whetherAttention = 0;
            this.$message.success({
              message: "取消订阅成功",
              type: "success"
            });
          } else {
            this.$message.error(res.message);
          }
        });
      }
    },
    // 订阅
    attention(id, keyWord) {
      let params = {
        departmentId: id,
        keywords: keyWord
      };
      departmentAttention(params).then(res => {
        if (res.code === 10001) {
          this.$refs.login.open();
        } else if (res.code === 10002) {
          this.isDepart = 1;
          this.departmentDialogVisible = true;
        } else if (res.code == 200) {
          this.articleDetails.whetherAttention = 1;
          this.$message({
            type: "success",
            message: "订阅成功"
          });
        } else {
          this.$message({
            type: "warning",
            message: res.message
          });
        }
      });
    },
    showWeChat(val) {
      this.isShareWeChat = val;
    },
    canExport() {
      whetherCanExport().then(res => {
        if (res.code == 10001) {
          this.$refs.login.open();
        } else if (res.code == 10006) {
          this.isDepart = 0;
          this.departmentDialogVisible = true;
        } else if (res.code === 200) {
          whetherDownload({ source: "0", policyId: this.policyId });
          noticeDownloadExcel({ policyId: this.policyId }).then(res => {
            let blob = new Blob([res.data]);
            let link = document.createElement("a");
            let fileName = "可申报企业名单.xls";
            link.href = window.URL.createObjectURL(blob);
            link.download = decodeURIComponent(fileName);
            link.click();
          });
        }
      });
    },
    // 下载名单
    exportName() {
      // whetherDownload({source: '0'})
      this.canExport();
    },
    // 去政策解读
    toRoute() {
      let params = {};
      let provinceName = sessionTake("provinceName");
      let cityName = sessionTake("cityName");
      if (provinceName && cityName) {
        params.province = provinceName;
        params.city = cityName;
        this.$router.push({
          name: "governmentUnscramble",
          params: params
        });
      } else {
        this.$router.push({
          name: "governmentUnscramble"
        });
      }
    },
    // 去政策订阅
    toSubscriptionpage() {
      let params = {};
      let provinceName = sessionTake("provinceName");
      let cityName = sessionTake("cityName");
      if (provinceName && cityName) {
        params.province = provinceName;
        params.city = cityName;
        this.$router.push({
          name: "subscriptionpage",
          params: params
        });
      } else {
        this.$router.push({
          name: "subscriptionpage"
        });
      }
    }
  }
};
</script>
<style lang="less" scoped>
/deep/.el-dialog__footer {
  height: 310px;
}

.contents_qydb {
  width: 200px;
  margin-left: 22px;
  margin-top: 20px;

  .goVip {
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 55px;
    align-items: center;
    justify-content: center;
    width: 100%;
    left: 0;

    .top {
      font-size: 14px;
      color: #000;
    }

    .bn {
      font-size: 14px;
      color: #1d78de;
    }
  }
}

.el-dialog__footer {
  height: 340px;
  position: relative;
}

.option {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 40px;
  bottom: 10px;
  width: 100%;
  font-size: 14px;
  left: 0;

  .spans_qydb {
    background-color: #bfbfbf;
    padding: 4px 30px;
    color: #fff;
    cursor: pointer;
    border-radius: 30px;
  }

  .ps_qydb {
    border-radius: 30px;

    background-color: #1d78de;
    padding: 4px 30px;
    color: #fff;
    cursor: pointer;
    // bottom: 15px;
    // right: 26px;
    // width: 159px;
    // height: 44px;
    // cursor: pointer;
  }
}

.el-dialog {
  border-radius: 10px;
}

.imgs_qydb {
  width: 100%;
  border-radius: 10px;
}

//@import url(); 引入公共css类
.mincard {
  span {
    font-size: 14px;
    margin: 0 10px;
    cursor: pointer;
  }
}

.details_main_content {
  background-color: #fff;

  .details_content_title {
    font-size: 28px;
    font-weight: 700;
    color: #333;
    padding: 30px 0;
    border-bottom: 1px solid #ccc;
  }

  .tampTime {
    height: 80px;
    display: flex;
    align-items: center;

    span {
      margin-right: 20px;
      font-size: 14px;
      color: #999;

      &.more {
        color: #44a2ff;
        margin-left: 20px;
      }

      em {
        font-style: normal;
        cursor: pointer;
        transition: all 0.2s;

        &:hover {
          color: rgb(68, 162, 255);
        }
      }
    }
    .export {
      font-weight: 600;
      font-size: 18px;
      color: red;
      cursor: pointer;
    }

    button {
      padding: 5px 10px;
      font-size: 14px;
      border: 1px solid #44a2ff;
      border-radius: 4px;
      background-color: #fff;
      color: #44a2ff;

      &.active {
        background-color: #999;
        border: none;
        color: #fff;
      }
    }
  }

  .declare {
    margin: 20px 0;

    .declare_title {
      padding-left: 10px;
      display: flex;
      align-items: center;
      height: 50px;
      color: #44a2ff;
      background-color: #f2f8fc;
      border-radius: 6px;
      font-size: 16px;
      font-weight: 700;
    }

    .declare_centent {
      margin: 20px 0;
      font-size: 16px;
      color: #333;
    }
  }

  .share {
    font-size: 14px;
    /*color: #ccc;*/
    display: flex;
    align-items: center;
    padding: 30px 0;

    img {
      width: 20px;
      margin: 0 10px;
    }

    i {
      margin-left: 10px;
      font-style: normal;
    }
  }
}

/deep/ .el-button {
  border: none !important;
}
</style>
